
#import "AblumView.h"

@implementation AblumView
- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        _singleScroll=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, kDeviceWidth, kDeviceHeight)];
        //缩放
        _singleScroll.maximumZoomScale=2.5;
        _singleScroll.minimumZoomScale=1;
        _singleScroll.showsHorizontalScrollIndicator=NO;
        _singleScroll.showsVerticalScrollIndicator=NO;
        _singleScroll.delegate=self;
        _singleScroll.scrollsToTop=NO;
        [self addSubview:_singleScroll];
        
        _imageview=[[UIImageView alloc]initWithFrame:_singleScroll.frame];
        _imageview.contentMode=UIViewContentModeScaleAspectFill;
        _imageview.backgroundColor=[UIColor clearColor];
        
        [_singleScroll addSubview:_imageview];
        
        UITapGestureRecognizer *singleTap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(hiddenORshow:)];
        [self addGestureRecognizer:singleTap];
        
        UITapGestureRecognizer *doubleTap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(ZoomOutorIn:)];
        doubleTap.numberOfTapsRequired=2;
        [self addGestureRecognizer:doubleTap];
        
        [singleTap requireGestureRecognizerToFail:doubleTap];

        // Initialization code
    }
    return self;
}
-(void)downloadImage
{
    if (_imageview.image==nil) {
        [_imageview setImageWithURL:[NSURL URLWithString:_url]];
    }
}


//双击放缩
-(void)ZoomOutorIn:(UITapGestureRecognizer *)tap
{
    CGPoint point=[tap locationInView:_imageview];
    if (_singleScroll.zoomScale>1) {
        _singleScroll.zoomScale=1;
    }
    else
    {
        [_singleScroll zoomToRect:CGRectMake(point.x-40, point.y-40, 80, 80) animated:YES];
    }
}

#pragma 代理
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
    return _imageview;
}

//单击隐藏
-(void)hiddenORshow:(UITapGestureRecognizer *)tap
{
    if ([self.delegate respondsToSelector:@selector(hiddenORshow:)]) {
        [self.delegate hiddenORshow:self];
    }
}


@end
